//
//  ResumePreImageViewController.m
//  eshow
//
//  Created by Hisoka on 16/2/25.
//  Copyright © 2016年 Hisoka. All rights reserved.
//

#import "ResumePreImageViewController.h"

@interface ResumePreImageViewController ()

@property (nonatomic, strong) UIScrollView *preImageSV;
@property (nonatomic, strong) UIButton *cancelBTN;

@end

@implementation ResumePreImageViewController

- (void) viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setStyle];
}

- (void) setStyle {
    
    int imageHeight = ScreenWidth / ([UIImage imageNamed:_imageName].size.width / [UIImage imageNamed:_imageName].size.height);
    
    self.preImageSV = [UIScrollView newAutoLayoutView];
    [self.view addSubview:_preImageSV];
    
    [_preImageSV autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.view];
    [_preImageSV autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.view];
    [_preImageSV autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.view];
    [_preImageSV autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.view];
    
    _preImageSV.backgroundColor = WHITE_COLOR;
    if ([_imageName isEqualToString:@"resume01Bg"]) {
        _preImageSV.contentSize = CGSizeMake(ScreenWidth , imageHeight + 100);
    }else{
        _preImageSV.contentSize = CGSizeMake(ScreenWidth , imageHeight);
    }
    _preImageSV.contentOffset = CGPointMake(0, 0);
    _preImageSV.pagingEnabled = NO;
    _preImageSV.showsHorizontalScrollIndicator = NO;
    _preImageSV.showsVerticalScrollIndicator = NO;
    
    int imageY = 0;
    
    if (imageHeight < ScreenHeight) imageY = 50;
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageY, ScreenWidth, imageHeight)];

    image.image = [UIImage imageNamed:_imageName];
    
    [_preImageSV addSubview:image];
    
    self.cancelBTN = [UIButton newAutoLayoutView];
    [self.view addSubview:_cancelBTN];
    
    [_cancelBTN autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.view withOffset:30];
    [_cancelBTN autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.view withOffset:10];
    [_cancelBTN autoSetDimensionsToSize:CGSizeMake(25, 25)];
    _cancelBTN.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_cancelBTN setBackgroundColor:[UIColor clearColor]];
//    [_cancelBTN setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelBTN setBackgroundImage:[UIImage imageNamed:@"cancelBTN"] forState:UIControlStateNormal];
    [_cancelBTN addTarget:self action:@selector(cancelPreImage) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark - 取消预览
- (void) cancelPreImage {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
